//    Copyright 2021 Cardinal
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
import javax.swing.Box;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class homework_1 {
    public static void main(String[] args) {
        var window = new JFrame("N");
        var vbox = Box.createVerticalBox();
        window.setLocationRelativeTo(null);//窗体居中显示
        window.setSize(300, 200);
        window.setResizable(false);
        window.add(vbox);
        var lbl_mousePos = new JLabel("此处显示鼠标右键点击的坐标");
        vbox.add(lbl_mousePos);
        window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        window.setVisible(true);
        window.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseClicked(MouseEvent e)
            {
                if(e.getButton() == MouseEvent.BUTTON3)
                {
                    lbl_mousePos.setText("点击鼠标右键时，位置为x:" + e.getX() + " y:" + e.getY());
                }
            }
        } );
    }
}